/*
 * @Descripttion:
 * @Author: YuZhenJing
 * @Date: 2020-01-01 12:42:27
 * @LastEditors: YuZhenJing
 * @LastEditTime: 2020-05-18 16:45:05
 */
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin')
let proxy = {
  '/asmcore': {
    target: 'http://localhost:9891',
    changeOrigin: true,
    pathRewrite: {
      '^/asmcore': '/asmcore',
    },
  },
}
module.exports = {
  transpileDependencies: [
    'element-ui',
    'asm-client',
    'vuex',
    'vue-nav-tree',
    'vue-particles',
  ],
  lintOnSave: false,
  devServer: {
    port: 8601,
    historyApiFallback: { index: '/' },
    headers: {
      'Access-Control-Allow-Origin': '*',
    },
    proxy: process.env.VUE_APP_SINGLERUN == 'true' ? proxy : null,
  },
  outputDir:
    process.env.VUE_APP_SINGLERUN !== 'true' ? '../../dist/asmCore' : 'dist',
  publicPath: process.env.VUE_APP_publicPath,
  chainWebpack: (config) => {
    if (process.env.VUE_APP_SINGLERUN !== 'true') {
      config.externals([
        'vue',
        { 'vue-router': 'vueRouter' },
        { 'element-ui': 'elementUI' },
        'axios',
      ])
    }
    config.plugin('script-ext-html').use(ScriptExtHtmlWebpackPlugin, [
      {
        custom: {
          test: /app.*\.js$/,
          attribute: 'entry',
          value: true,
        },
      },
    ])
    config.output
      .libraryTarget('umd')
      .library('')
      .jsonpFunction('webpackJsonp_asm-core')
  },
  css: {
    loaderOptions: {
      postcss: {
        plugins: [
          require('postcss-plugin-namespace')('.asm-core', {
            ignore: ['*', '#app', /body/],
          }),
        ],
      },
      stylus: {
        import: '~@/css/styles/app.styl',
      },
    },
  },
}
